package com.sulent.frame.support.utils;

import cn.hutool.crypto.asymmetric.KeyType;
import cn.hutool.crypto.asymmetric.RSA;

/**
 * @ClassName PasswordUtils
 * @Description: 基于Hutool工具包RSA算法
 * @Author Submerge.
 * @Since 2024/1/18 16:45
 * @Version 1.0
 */
public class PasswordUtils {


    public static String getRsaAlgorithmKey(){
        RSA rsa = new RSA();
        String publicKeyBase64 = rsa.getPublicKeyBase64();
        String privateKeyBase64 = rsa.getPrivateKeyBase64();
        return "RSA算法：\n\t公钥:"+publicKeyBase64+"\n\t私钥:"+privateKeyBase64;
    }

    public static String rsaEncryptByPublicKey(String publicKey,String decryptData){
        RSA rsa = new RSA(null,publicKey);
        return rsa.encryptBase64(decryptData, KeyType.PublicKey);
    }

    public static String rsaDecryptByPrivateKey(String privateKey,String decryptData){
        RSA rsa = new RSA(privateKey,null);
        return rsa.decryptStr(decryptData, KeyType.PrivateKey);
    }

}
